package com.icebergteam.warfacewidget.core;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class NotificationService extends Service {
	private NotificationManager nm;
	public static String className = NotificationService.class.getCanonicalName();

	public static String KEY_NOTIF_MESSAGE = String.format("%s.%s", className, "KEY_NOTIF_MESSAGE");

	@Override
	public void onCreate() {
		super.onCreate();
		nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	}

	public int onStartCommand(Intent intent, int flags, int startId) {
		sendNotif(intent);
		return super.onStartCommand(intent, flags, startId);
	}

	void sendNotif(Intent intent) {
		NotificationMessage message = intent
				.getParcelableExtra(NotificationService.KEY_NOTIF_MESSAGE);
		Notification notif = message.toBaseNotification();
		nm.notify(message.getId(),
				notif);
		this.stopSelf();
	}

	public IBinder onBind(Intent arg0) {
		return null;
	}
}